using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using UmlDesigner.Model;

namespace UmlDesigner.Gui
{
    public partial class CodeGenerationForm : Form
    {
        public CodeGenerationForm(string defaultNamespaceName)
        {
            InitializeComponent();
            Icon = Properties.Resources.ApplicationIcon;

            namespaceTextBox.Text = defaultNamespaceName;

            SetupCheckBoxes();
        }

        private void findOutputDirButton_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog(this) == DialogResult.OK)
            {
                outDirTextBox.Text = folderBrowserDialog.SelectedPath;
            }
        }

        private CodeGenerationSettings settings;

        internal CodeGenerationSettings GenerationSettings
        {
            get
            {
                return settings;
            }
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            CodeGenerationSettings.GenerationSource src = CodeGenerationSettings.GenerationSource.CurrentDocument;
            if (selOnlyRadioButton.Checked)
            {
                src = CodeGenerationSettings.GenerationSource.SelectionOnly;
            }
            else if (allDocsRadioButton.Checked)
            {
                src = CodeGenerationSettings.GenerationSource.AllDocuments;
            }

            settings = new CodeGenerationSettings(outDirTextBox.Text, namespaceTextBox.Text, src, createSolutionCheckBox.Checked, createProjectCheckBox.Checked, createDirForProjCheckBox.Checked);
        }

        private void SetupCheckBoxes()
        {
            if (createProjectCheckBox.Checked)
            {
                createSolutionCheckBox.Enabled = true;
            }
            else
            {
                createSolutionCheckBox.Enabled = false;
                createSolutionCheckBox.Checked = false;
            }

            if (createSolutionCheckBox.Checked)
            {
                createDirForProjCheckBox.Enabled = true;
            }
            else
            {
                createDirForProjCheckBox.Enabled = false;
                createDirForProjCheckBox.Checked = false;
            }
        }

        private void createProjectCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            SetupCheckBoxes();
        }

        private void createSolutionCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            SetupCheckBoxes();
        }

        private void createDirForProjCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            SetupCheckBoxes();
        }
    }
}